home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / arexxcomm.lha / ARexxComm-R.e next >
Text File  |  1999-03-21  |  3KB  |  85 lines

  1. /* ARexxComm-R - a program to demo/test the module ARexxComm */
  2.  
  3. MODULE 'CSH/arexxcomm'
  4.  
  5. ->how to create a port, send a message, wait for a message, & close a port
  6. PROC main() HANDLE
  7.  DEF portinfo=NIL:PTR TO rxcom, portname=NIL:PTR TO CHAR,
  8.      command=NIL:PTR TO CHAR, args=NIL:PTR TO CHAR,
  9.      cmdknown, quit=FALSE, wasack=FALSE
  10.     portname:='ExampleHost'
  11.     WriteF('ARexxComm-R program\nPress Ctrl-C to quit, or send the QUIT command\n')
  12.     WriteF('1.To send a command type at another shell: Sys:RexxC/Rx "Address \a\s\a \aCOMMAND\a"\n2.Known commands: SAYYO, SAYHI, QUIT\n\n',portname)
  13.  
  14.     NEW portinfo.createPort(portname,{portinfo})
  15.     IF portinfo
  16.         IF portinfo.portExists('TestHost')
  17.             WriteF('I see that "TestHost" is already running!\n')
  18.         ELSE
  19.             WriteF('Why not try running ARexxComm-S ("TestHost")?\n')
  20.         ENDIF
  21.          ->portinfo.sendRexxMsg('GOLDED.1','UP')
  22.          ->portinfo.sendRexxMsg('REXX','scriptname')
  23.          ->portinfo.sendRexxMsg(portname,'QUIT')
  24.  
  25.         WriteF('Sent RexxMaster a command to run "list ram:"\n')
  26.         portinfo.sendRexxMsg('REXX','"ADDRESS COMMAND \alist ram:\a"')
  27.  
  28.         REPEAT
  29.             cmdknown:=FALSE
  30.             command,args:=portinfo.waitForRexxMsg()            ->get a command (uses zero CPU time)
  31.             ->command,args,wasack:=portinfo.waitForRexxMsg(TRUE)    ->get a command (uses zero CPU time), may instead return wasack=TRUE (recieved acknowledge of our message)
  32.             /*REPEAT                        ->get a command (uses LOTS of CPU time - "busy waiting")
  33.                 command,args,wasack:=portinfo.waitForRexxMsg(TRUE)
  34.             UNTIL (command<>NIL) OR wasack*/
  35.  
  36.             IF wasack=TRUE        ->don't need this IF statement if waitRexxMsg() is used above
  37.                 WriteF('  Happy! Happy! Joy! Joy!  Recieved acknowledgement our message was recieved!\n')
  38.             ELSE
  39.                  /* code to deal with commands */
  40.                 IF command                ->you *must* check for this! (command=NIL if recieve Ctrl-C)
  41.                     WriteF('#I recieved the "\s" Rexx command.\n',command)
  42.                     IF StrCmp('SAYYO',command)
  43.                         WriteF('Yo')
  44.                         IF args[0]<>"\0" THEN WriteF(' "\s"!\n',args) ELSE WriteF('!\n')
  45.                         cmdknown:=TRUE
  46.                     ELSEIF StrCmp('SAYHI',command)
  47.                         WriteF('Hi')
  48.                         IF args[0]<>"\0" THEN WriteF(' "\s"!\n',args) ELSE WriteF('!\n')
  49.                         cmdknown:=TRUE
  50.                     ELSEIF StrCmp('QUIT',command)
  51.                         quit:=TRUE
  52.                         cmdknown:=TRUE
  53.                     ENDIF
  54.                     portinfo.ackRexxMsg(cmdknown)
  55.                 ELSE
  56.                     quit:=TRUE
  57.                 ENDIF
  58.             ENDIF
  59.  
  60.             ->this sends ourself a message that is never read (waited for or polled), as we quit soon after; this used to cause END to freeze miggy
  61.             /*IF quit OR (command=FALSE)
  62.                 WriteF('Sent myself a SAYYO command\n')
  63.                 portinfo.sendRexxMsg(portname,'SAYYO ExampleHost')
  64.             ENDIF*/
  65.         UNTIL quit
  66.  
  67.         END portinfo
  68.     ENDIF
  69. EXCEPT
  70.     WriteF('ERROR:  ')
  71.     SELECT exception
  72.         CASE "LIB";    WriteF('Could not open library "\s"!\n',exceptioninfo)
  73.         CASE "PORT";    WriteF('Could not open ARexx port "\s"!\n',exceptioninfo)
  74.         CASE "RXNA";    WriteF('Did not acknowledge previous ARexx message "\s"!\n',exceptioninfo)
  75.         CASE "RXNM";    WriteF('No ARexx message to acknowledge!\n')
  76.         CASE "RXCM";    WriteF('\s!\n')
  77.         DEFAULT;    IF exceptioninfo
  78.                     WriteF('"\c"; \s.\n',exception,exceptioninfo)
  79.                 ELSE
  80.                     WriteF('"\c".\n',exception)
  81.                 ENDIF
  82.     ENDSELECT
  83.     IF portinfo THEN END portinfo        ->only close port if it has not been closed already
  84. ENDPROC
  85.